import request from './request'

// 考核方案数据类型
export interface AssessmentData {
  id: number
  name: string
  period: 'monthly' | 'quarterly' | 'yearly'
  month: string
  department: string
  departmentIds: number[]
  status: 'draft' | 'in_progress' | 'completed'
  progress: number
  kpiIds: number[]
  process: ProcessStep[]
  remark: string
  createTime: string
}

// 流程步骤数据类型
interface ProcessStep {
  name: string
  description: string
  handlers: number[]
  timeLimit: number
}

// 获取考核方案列表
export const getAssessmentList = (params: {
  department?: number
}) => {
  return request({
    url: '/assessments/list',
    method: 'post',
    data: params
  })
}

// 获取考核方案分页列表
export const getAssessmentPage = (params: {
  current: number
  size: number
  name?: string
  period?: string
  status?: string
}) => {
  return request({
    url: '/assessments/page',
    method: 'post',
    data: params
  })
}

// 新增考核方案
export const addAssessment = (assessment: Omit<AssessmentData, 'id' | 'createTime'>) => {
  return request({
    url: '/assessments/add',
    method: 'post',
    data: assessment
  })
}

// 编辑考核方案
export const updateAssessment = (assessment: AssessmentData) => {
  return request({
    url: '/assessments/update',
    method: 'post',
    data: assessment
  })
}

// 删除考核方案
export const deleteAssessment = (id: number) => {
  return request({
    url: '/assessments/delete',
    method: 'post',
    data: { id }
  })
}

// 获取考核方案详情
export const getAssessmentDetail = (id: number) => {
  return request({
    url: '/assessments/detail',
    method: 'post',
    data: { id }
  })
}

// 切换考核方案状态
export const toggleAssessmentStatus = (id: number) => {
  return request({
    url: '/assessments/toggle-status',
    method: 'post',
    data: { id }
  })
}

// 获取考核方案统计数据
export const getAssessmentStats = () => {
  return request({
    url: '/assessments/stats',
    method: 'post',
    data: {}
  })
}

// steps
export const getSteps = (id: number) => {
  return request({
    url: '/assessments/steps',
    method: 'post',
    data: {
        id
    }
  })
}

// kpis
export const getAssessmentKPIs = (id: number) => {
  return request({
    url: '/assessments/kpis',
    method: 'post',
    data: {
      id
    }
  })
}

// publish
export const publishAssessment = (id: number) => {
  return request({
    url: '/assessments/publish',
    method: 'post',
    data: {
      id
    }
  })
}
